package com.ruoyi.ctcx.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ctcx.domain.TbInsuranceAttachment;
import com.ruoyi.ctcx.domain.TbInsuranceMain;
import com.ruoyi.ctcx.domain.ro.InsuranceParam;
import com.ruoyi.ctcx.domain.vo.*;
import com.ruoyi.ctcx.service.ITbInsuranceAttachmentService;
import com.ruoyi.ctcx.service.ITbInsuranceMainService;
import com.ruoyi.ctcx.service.ITbInsuranceSettleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;

/**
 * 首页大屏
 * 
 * @author ruoyi
 * @date 2024-11-19
 */
@RestController
@RequestMapping("/insurance/index")
public class TbInsuranceIndexController extends BaseControllerExt
{
    @Autowired
    private ITbInsuranceMainService tbInsuranceMainService;


    @Autowired
    private ITbInsuranceSettleService tbInsuranceSettleService;



    /**
     * 展示区1
     * 风控服务公司可以看到所有数据
     * 经纪/代理公司统计自己
     */
    @GetMapping("/getTotal")
    public AjaxResult getTotal(InsuranceParam insuranceParam)
    {
        //保险项目累计保费支出
        initDeptId(insuranceParam);
        TbInsuranceTotalVo totalVo = tbInsuranceMainService.getTotalFee(insuranceParam);

        //计算未收风控及技术服务费
        BigDecimal riskAmountTotal = totalVo.getRiskAmountTotal();//风控及技术服务费总额
        BigDecimal riskAmountRealTotal =  totalVo.getRiskAmountRealTotal();//已收风控及技术服务费

        BigDecimal riskAmountNoTotal = riskAmountTotal.subtract(riskAmountRealTotal);
        totalVo.setRiskAmountNoTotal(riskAmountNoTotal);

        return success(totalVo);
    }


    /**
     * 展示区2
     * 投保人排名展示（按保费支出排名，展示前五名），包含投保人名称，保费支出，累计赔款收入
     * 风控服务公司可以看到所有数据
     * 经纪/代理公司统计自己
     */
    @GetMapping("/getPaimingList")
    public AjaxResult getPaimingList(InsuranceParam insuranceParam)
    {
        //保险项目累计保费支出
        initDeptId(insuranceParam);
        List<TbInsurancePaimingVo> list = tbInsuranceMainService.getPaimingList(insuranceParam);

        return success(list);
    }

}
